# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :str_folders_size.py
# @Time      :2023/11/12 12:09
# @Author    :WangXiang


import os
import random
import string

def generate_random_text(size):
    # 生成指定大小的随机英文字符
    return ''.join(random.choices(string.ascii_letters, k=size))

def generate_folder_with_files(folder_size_gb, num_files):
    # 生成指定大小的文件夹和指定数量的文件
    folder_name = "Folder"
    os.makedirs(folder_name, exist_ok=True)

    # 将文件夹大小转换为字节
    folder_size_bytes = int(folder_size_gb * 1024 * 1024 * 1024)  # GB转换为字节

    # 计算每个文件的大小
    avg_file_size_bytes = folder_size_bytes // num_files

    for i in range(num_files):
        # 随机生成每个文件的大小
        file_size_bytes = avg_file_size_bytes
        file_name = f"File{i+1}.txt"

        # 生成随机文本内容
        file_content = generate_random_text(file_size_bytes)

        # 写入文件
        with open(os.path.join(folder_name, file_name), 'w') as file:
            file.write(file_content)

generate_folder_with_files(1.5, 500)